package com.cogwheel.framework.graphics.ui;

import javax.media.opengl.GL2;

import com.cogwheel.framework.graphics.CSprite;
import com.cogwheel.framework.init.CPreferences;
import com.cogwheel.framework.util.CAssets;
import com.cogwheel.framework.util.CRectangle;
import com.cogwheel.framework.util.CUtils;
import com.cogwheel.framework.util.input.CKeyboard;
import com.cogwheel.framework.util.input.CMouse;
import com.cogwheel.framework.util.input.CMouseState;

public class CCheckBox extends CSprite {
	private String TextureID2;
	public boolean Checked = false;
	
	public CCheckBox(CPreferences preferences, String spriteID, String spriteID2, CRectangle dimensions) {
		super(preferences, spriteID, dimensions);
		this.TextureID2 = spriteID2;
	}
	
	@Override
	public void CBindTexture(GL2 gl){
		if (Checked){
			if (TextureID2 != null && CUtils.CurrentTexture != TextureID2){
				CAssets.CWGGetTexture(TextureID2).enable(gl);
				CAssets.CWGGetTexture(TextureID2).bind(gl);
				
				CUtils.CurrentTexture = TextureID2;
			}
		}else{
			if (TextureID != null && CUtils.CurrentTexture != TextureID){
				CAssets.CWGGetTexture(TextureID).enable(gl);
				CAssets.CWGGetTexture(TextureID).bind(gl);
				
				CUtils.CurrentTexture = TextureID;
			}
		}
	}

	@Override
	public void CUpdate(CMouse mouse, CKeyboard keyboard){
		if (Dimensions.Intersects(new CRectangle(mouse.CWGGetMouseCoords(), 1, 1)) && mouse.CWGGetMouseState() == CMouseState.RIGHT_DOWN){
			if (Checked) Checked = false;
			else Checked = true;
			
			mouse.CWGSetMouseState(CMouseState.NOTHING);
		}
	}
	
}
